using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using QuadAnimation.Primitives.Shapes;

namespace QuadAnimation.Animation
{
    public abstract class AnimationHelper
    {
        public static void SetCurrentAnimation(Quad quad, AnimationSettings settings, int currentFrame, Boolean flip)
        {
            Vector2 upperLeft, upperRight, lowerRight, lowerLeft;
            float frameWidthMultiplier = (float)settings.animationWidth / (float)settings.textureWidth;
            float frameHeightMultiplier = (float)settings.animationHeight / (float)settings.textureHeight;

            int col = currentFrame % settings.framesPerRow;
            int row = (int)Math.Floor((double)currentFrame / (double)settings.framesPerRow);

            upperLeft = new Vector2(col * frameWidthMultiplier, row * frameHeightMultiplier);
            upperRight = upperLeft + new Vector2(frameWidthMultiplier, 0);
            lowerRight = upperRight + new Vector2(0, frameHeightMultiplier);
            lowerLeft = upperLeft + new Vector2(0, frameHeightMultiplier);

            quad.SetTextureCoordinates(upperLeft, upperRight, lowerRight, lowerLeft, flip);
        }
    }
}
